<?php 
//连接数据库
include '../common/mysql_connect.php';
header("content-Type:text/html;charset=utf-8");
$bool=Linking();
if (!$bool){
    echo "连接出错";
}else {
    $getclass=$_GET['class'];
    $getsql=$_GET['sql'];
    $getposition=$_GET['position'];
    switch ($getclass) {
      case 'card':
        $class="卡片";
        break;
      case 'money':
        $class="财物";
        break;
      case 'other':
        $class="其他";
        break;
      default:
        $class="";
        break;
    }
    switch ($getsql) {
      case 'lost':case 'found':break;
      default:$getsql='lost';break;
    }
    switch ($getposition) {
      case 'north':case 'south':break;      
      default:$getposition="";break;
    }
    //得到所有数据
    if ($class=="") {
      if ($getposition=="") {
        $sql="select * from `lost&found` where `lost&found`=\"".$getsql."\" ORDER BY `date` DESC";
      }else{
        $sql="select * from `lost&found` where `lost&found`=\"".$getsql."\" and `position`=\"".$getposition."\" ORDER BY `date` DESC";
      }
    }else{
      if ($getposition=="") {
        $sql="select * from `lost&found` where `lost&found`=\"".$getsql."\" and `class`=\"".$class."\" ORDER BY `date` DESC";
      }else{
        $sql="select * from `lost&found` where `lost&found`=\"".$getsql."\" and `position`=\"".$getposition."\" and `class`=\"".$class."\" ORDER BY `date` DESC";
      }
    }
    $result=mysql_query($sql);
    $totalNum=@mysql_num_rows($result);//得到数据条数

    $each=4;
    $totalPage=ceil($totalNum/$each);//$each为每页显示条数
    
    //得到当前页
    $page=$_GET['page'];
    
    if(empty($page)||$page<=0){
        $page=1;
    }else if ($page>=$totalPage){
        $page=$totalPage;
    }
    
    $begin=$each*($page-1);
    if ($class=="") {
      if ($getposition=="") {
        $fetchsql="select * from `lost&found` where `lost&found`=\"".$getsql."\" ORDER BY `date` DESC,`id` DESC limit ".$begin.",".$each."";
      }else{
        $fetchsql="select * from `lost&found` where `lost&found`=\"".$getsql."\" and `position`=\"".$getposition."\" ORDER BY `date` DESC,`id` DESC limit ".$begin.",".$each."";
      }
    }else{
      if ($getposition=="") {
        $fetchsql="select * from `lost&found` where `lost&found`=\"".$getsql."\" and `class`=\"".$class."\" ORDER BY `date` DESC,`id` DESC  limit ".$begin.",".$each."";
      }else{
        $fetchsql="select * from `lost&found` where `lost&found`=\"".$getsql."\" and `position`=\"".$getposition."\" and `class`=\"".$class."\" ORDER BY `date` DESC,`id` DESC  limit ".$begin.",".$each."";
      }
    }
    $fetchresult=mysql_query($fetchsql);
}

?>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>权小益失物招领</title>
    <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
      <style type="text/css" media="screen">
          .color{color:#2a6496}
           .footer {
            text-align:center;
            position: relative;
            font-size:80%;
            margin-top: 30px;
            line-height:60%;
        }
          .li_width{width:32.8%;}
          .hr_height{height:1px;position:relative;top:-10px;}
          .dropdown-menu {
              position: absolute;
              top: 100%;
              left: 0;
              z-index: 1000;
              display: none;
              float: left;
              min-width: 100px;
              padding: 5px 0;
              margin: 2px 0 0;
              font-size: 14px;
              text-align:center;
              list-style: none;
              background-color: #fff;
              -webkit-background-clip: padding-box;
                      background-clip: padding-box;
              border: 1px solid #ccc;
              border: 1px solid rgba(0, 0, 0, .15);
              border-radius: 4px;
              -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
                      box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
            }
      </style>
  </head>
  <body>
   <div class="container-fliud">
       <ul class="nav nav-tabs" role="tablist">
       <!--类型-->
           <li class="li_width" role="presentation" style="text-align: center; '微软雅黑'"><a href="output.php"><font color="black"><strong>全部</strong></font></a></li>
           <li class="li_width" role="presentation" class="dropdown" style="text-align: center; '微软雅黑'"><a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false"><font color="black"><strong>所在校区</strong></font><span class="caret"></span></a>
                <ul class="dropdown-menu" role="menu">
                    <li role="presentation"><?php echo '<a href="'.$_SERVER["PHP_SELF"].'?position=north">五山校区</a>';?></li>
                    <li role="presentation"><?php echo '<a role="menuitem" href="'.$_SERVER["PHP_SELF"].'?position=south">大学城校区</a>';?></li>
                </ul>
            </li>            
           <li class="li_width" role="presentation" class="dropdown" style="text-align: center; '微软雅黑'"><a href="#" class="dropdown-toggle" data-toggle="dropdown"  role="button" aria-expanded="false"><font color="black"><strong>物品类别</strong></font><span class="caret"></span></a>
                <ul class="dropdown-menu" >
                    <li role="presentation"><?php echo '<a role="menuitem"  tabindex="-1"  href="'.$_SERVER["PHP_SELF"].'?position='.$getposition.'&sql='.$getsql.'&class=card">卡类</a>';?></li>
                    <li role="presentation"><?php echo '<a role="menuitem"  tabindex="-1"  href="'.$_SERVER["PHP_SELF"].'?position='.$getposition.'&sql='.$getsql.'&class=money">财物</a>';?></li>
                    <li role="presentation"><?php echo '<a role="menuitem"  tabindex="-1"  href="'.$_SERVER["PHP_SELF"].'?position='.$getposition.'&sql='.$getsql.'&class=other">其他</a>';?></li>
                </ul>
            </li>

       </ul>
    </div>
<div class="container">
<!--失物招领-->
      <ul class="nav nav-pills nav-stacked">
      <li role="presentation" <?php if($getsql!="found") echo 'class="active"';?> >
        <?php echo '<a href="'.$_SERVER["PHP_SELF"].'?position='.$getposition.'&sql=lost"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>&nbsp;遗失信息</a>';?>
      </li>
      <li role="presentation" <?php if($getsql=="found") echo 'class="active"';?>>
        <?php echo '<a href="'.$_SERVER["PHP_SELF"].'?position='.$getposition.'&sql=found"><span class="glyphicon glyphicon-bullhorn" aria-hidden="true"></span>&nbsp;招领信息</a>';?>
      </li>
      <li role="presentation">
        <a href="input.php"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;发布信息</a>
      </li>
    </ul>
 </div>
    <hr>
    <!--以下就是从数据库导出数据的部分，提供两个框架-->
    <?php
    if (!$bool){
        echo "连接出错";
    }else {
      if ($totalNum==0) {
        echo "<br><br><h4>&nbsp;&nbsp;&nbsp;&nbsp;亲，暂时没有您需要的信息哦:)</h4>";
      }else{
        $i=0;
        while ($row=mysql_fetch_array($fetchresult)){
          $i++;
          echo '<nav class="navbar navbar-default">
          <div class="container-fluid">
            <div class="navbar-header">
            <img src="image/dot.png" width="25px" height="25px">
              <div class="color">
                  <ul >
                    <li style="list-style-type:none;"><font color="black" ><span class="glyphicon glyphicon-header"></span>&nbsp;标题：'.$row['title'].'</font></li>
                    <li style="list-style-type:none;"><font color="black" ><span class="glyphicon glyphicon-time"></span>&nbsp;时间：'.date("Y-m-d",$row['date']).'</font></li>
                    <li style="list-style-type:none;"><font color="black" ><span class="glyphicon glyphicon-road"></span>&nbsp;地点：'.$row['place'].'</font></li>
                    <li style="list-style-type:none;"><font color="black"><span class="glyphicon glyphicon glyphicon-asterisk"></span>&nbsp;类别：'.$row['class'].'</font></li>
          <div class="hr_height"><hr/></div>
                    <script type="text/JavaScript">
                    $(document).ready(function(){
                      $("'."#display".$i.'").click(function(){
                        $("'."#content".$i.'").toggle();
                      });
                    });
                    </script>
                    <div  class="nav nav-pills nav-stacked>
                    <li role="presentation"  id="display'.$i.'"><font color="black">点击查看更多...<span class="glyphicon glyphicon-chevron-down"></span>&nbsp;</font></li>
                    </div>
                    <div id="content'.$i.'" style="display:none">
                    
                    <li style="list-style-type:none;"><font color="black"><span class="glyphicon glyphicon-list-alt"></span>&nbsp;详情：'.$row['detail'].'</font></li>
                    <li style="list-style-type:none;"><font color="black"><span class="glyphicon glyphicon-user"></span>&nbsp;联系人：'.$row['contacter'].'</font></li>
                    <li style="list-style-type:none;"><font color="black"><span class="glyphicon glyphicon-phone"></span>&nbsp;电话：'.$row['tel'].'</font></li>
                    <li style="list-style-type:none;"><font color="black"><span class="glyphicon glyphicon-comment"></span>&nbsp;QQ：'.$row['qq'].'</font></li>
                    </div>
                    
                  </ul>
              </div>
            </div>
          </div>
        </nav>';
        }
    }
  }

   ?>
<div align="center">
<nav>
  <div class="page-header">
      <?php 
        if ($page>=$totalPage) {
          echo "已到达末页";
        }else if ($page<=1) {
          echo "已到达首页";
        }else{
          echo "已到达第".$page."页";
        }
      ?>
      </div>
  <!--分页-->
  <ul class="pagination">
    <li >
      <?php echo "<a href='".$_SERVER['PHP_SELF']."?positon=".$getposition."&sql=".$getsql."&class=".$getclass."&page=".($page-1)."'>上一页<span>&laquo;</span></a>"; ?>          
    </li>
    <li>

    </li>
    <li>
      <?php echo "<a href='".$_SERVER['PHP_SELF']."?positon=".$getposition."&sql=".$getsql."&class=".$getclass."&page=".($page+1)."'>下一页<span>&raquo;</span></a>"; ?>
    </li>
  </ul>
</nav>
</div>        
      
      <div class="footer"><br><p>Copyright© 2015华南理工大学学生会权益部</p><p>Power by无线电爱好者协会信息部 </p></div>
   

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>
